package com.seocoo.worker.user.account;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.seocoo.worker.R;
import com.seocoo.worker.base.http.BaseRsp;
import com.seocoo.worker.base.widget.AppToolBer;
import com.seocoo.worker.base.widget.DountChartView;
import com.seocoo.worker.user.account.entity.EAccount;
import com.seocoo.worker.user.account.model.AccountModel;
import com.sfh.lib.mvvm.LiveDataMatch;
import com.sfh.lib.ui.MVVMActivity;

import org.xclcharts.chart.DountChart;
import org.xclcharts.chart.PieData;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * author : Ssp
 * e-mail : 981297079@qq.com
 * date   : 2020/3/1614:02k
 * desc   : 我的账户首页
 * version: 1.0
 */
public class MyAccountHomeActivity extends MVVMActivity {

    public static void start(Context context) {
        context.startActivity(new Intent(context, MyAccountHomeActivity.class));
    }

    private AppToolBer appToolBer;
    private TextView tvAccountMoney;
    private TextView tvAllMoney;
    private TextView tvCashMoney;
    private FrameLayout flContent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_account_home);
        initView();
        StatusBarUtil.setTranslucentForImageView(this, 0, appToolBer);
        getViewModel(AccountModel.class).capitalAccount();
    }

    private void initView() {
        appToolBer = (AppToolBer) findViewById(R.id.appToolBer);
        tvAccountMoney = (TextView) findViewById(R.id.tvAccountMoney);
        tvAllMoney = (TextView) findViewById(R.id.tvAllMoney);
        tvCashMoney = (TextView) findViewById(R.id.tvCashMoney);
        flContent = (FrameLayout) findViewById(R.id.fl_content);
        findViewById(R.id.tv_detail).setOnClickListener(v -> {
            //提现明细
            DepositListActivity.start(MyAccountHomeActivity.this);
        });
        findViewById(R.id.tvCash).setOnClickListener(v -> {
            //提现->是否在提现日期
            getViewModel(AccountModel.class).queryChenkDeposit();
        });
        findViewById(R.id.tv_all_money).setOnClickListener(v -> {
            //资金奖励明细
            MoneyAllListActivity.start(MyAccountHomeActivity.this);
        });

    }
    @LiveDataMatch
    public void onChenkDepositSuccess(BaseRsp baseRsp){
        //提现
        if (baseRsp.success()){
            DepositActivity.start(MyAccountHomeActivity.this);
        }else {
            NoDepositDialog.showDialogUI(this,baseRsp.getMsg());
        }
    }

    @LiveDataMatch
    public void onCapitalAccount(EAccount account) {
        if (account != null){
            tvAllMoney.setText(account.totalMoney + "");
            tvCashMoney.setText(account.depositMoney + "");
            tvAccountMoney.setText(account.balanceMoney + "");
//            account.auditDeopsitRate = 35;
//            account.balanceRate = 25;
//            account.depositRate = 40;

            flContent.removeAllViews();
            DountChartView dountChartView = new DountChartView(this);
            dountChartView.chartDataSet(new PieData("审核中",  account.auditDeopsitRate+"%", account.auditDeopsitRate, Color.parseColor("#FF6880")));
            dountChartView.chartDataSet(new PieData("可提现",  account.balanceRate+"%",  account.balanceRate, Color.parseColor("#FEB543")));
            dountChartView.chartDataSet(new PieData("已提现", account.depositRate+"%", account.depositRate, Color.parseColor("#39CF9F")));

            flContent.addView(dountChartView);
        }
    }

}
